package com.woniu.rear.comm.redis.config;

import org.redisson.spring.data.connection.RedissonConnectionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

/**
 * redis模板类配置
 * @author liwei
 *
 */
@Configuration
public class RedisConfig {
	
	/**
	 * redis自定义模板类，值格式化json
	 * @param rcf
	 * @return
	 */
	@Bean("objTemplate")
	public RedisTemplate<String, Object> createTemplate(RedissonConnectionFactory rcf) {
		RedisTemplate<String, Object> rt = new RedisTemplate<>();
		rt.setConnectionFactory(rcf);
		rt.setValueSerializer(RedisSerializer.json());
		rt.setKeySerializer(RedisSerializer.string());
		rt.setHashKeySerializer(RedisSerializer.string());
		rt.setHashValueSerializer(RedisSerializer.json());
		return rt;
	}

}
